const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tasks: [],
    list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  addButton: function () {
    wx.navigateTo({
      url: '../vitae/input',
    })
  },
  detail: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);
    var contactUniqueId = that.data.list[index].contactUniqueId
    var name = that.data.list[index].name
    var avatarUrl = that.data.list[index].avatarUrl
    wx.navigateTo({
      url: './contact?contactUniqueId=' + contactUniqueId + 
      '&uniqueId='+app.globalData.uniqueId+
      '&name='+name+
      '&avatarUrl='+avatarUrl,
    })
    console.log(index)
  },
  option: function (e) {
    var that = this
    var index = parseInt(e.currentTarget.dataset.index);
    var id = this.data.list[index].id
    wx.showActionSheet({
      itemList: ['删除'],
      itemColor: "#DC143C",
      success: function (res) {
        if (!res.cancel) {
          wx.request({
            url: app.globalData.url + '/vitae/deleteVitae',
            data: {
              id: id,
            },
            success: res => {
              if (res.data.code == 0) {
                wx.showModal({
                  title: '提醒',
                  content: res.data.msg,
                })
              } else {
                that.onShow();
              }
            }
          })
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.request({
      url: app.globalData.url + '/msg/getContacts',
      data: {
        uniqueId: app.globalData.uniqueId
      },
      success: res => {
        var that = this
        console.log(res.data.contactVOList)
        that.setData({
          list: res.data.contactVOList
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})